<?php

namespace app\uniapp\controller;

use app\common\exception\MiException;
use app\service\upload\UploadService;
use app\uniapp\service\UniAuthService;
use think\Request;

class UploadController extends UniController
{

    /**
     * 不需要验证权限的请求
     */
    protected array $middleware = [];

    /**
     * @throws MiException
     */
    public function uploadImg(): \think\response\Json
    {
        $uploadSer = new UploadService();
        $siteId = UniAuthService::instance()->getSiteId();
        $file = $uploadSer->setSubPath("/site/{$siteId}")->upload($siteId, UniAuthService::instance()->getLoginId());
        return jsonSuccess([
            'file' => $file
        ]);
    }

    /**
     * @throws MiException
     */
    public function uploadFile(Request $request): \think\response\Json
    {
        $uploadSer = new UploadService();
        $disk = $request->param('disk',  'public');
        $siteId = UniAuthService::instance()->getSiteId();
        $file = $uploadSer->setDisk($disk)->setSubPath("/site/{$siteId}")->upload($siteId, UniAuthService::instance()->getLoginId());
        return jsonSuccess([
            'file' => $file
        ]);
    }

    /**
     * @throws MiException
     */
    public function uploadVideo(): \think\response\Json
    {
        $uploadSer = new UploadService();
        $siteId = UniAuthService::instance()->getSiteId();
        $file = $uploadSer->setSubPath("/site/{$siteId}")->upload($siteId, UniAuthService::instance()->getLoginId());
        return jsonSuccess([
            'file' => $file
        ]);
    }

}
